﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Windows.Controls;

namespace Tellstick_Registrator.UserControls
{
    /// <summary>
    /// Interaction logic for LabelValue.xaml
    /// </summary>
    public partial class LabelValue : UserControl, INotifyPropertyChanged
    {
        private LabelValueObject _labelValue;
        private ValidationError _validationError;

        public event PropertyChangedEventHandler PropertyChanged;

        public LabelValue()
        {
            InitializeComponent();
            _labelValue = new LabelValueObject();
            StackPanelContainer.DataContext = this;


            var ageRangeRule = new AgeRangeRule() { Min = 20, Max = 50, NotifyOnValidationError = true };
            _validationError = new ValidationError(ageRangeRule, txtValue.GetBindingExpression(TextBox.TextProperty));
            _validationError.ErrorContent = "This is not a valid e-mail address";

        }

        public string Label
        {
            get { return _labelValue.Label; }
            set
            {
                _labelValue.Label = value;
                if (null != this.PropertyChanged)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("Label"));
                }
            }
        }

        public string Value
        {
            get { return _labelValue.Value; }
            set
            {
                _labelValue.Value = value;
                if (null != this.PropertyChanged)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("Value"));
                }
            }
        }

    }

    public class LabelValueObject : INotifyPropertyChanged
    {

        private string _label;
        private string _value;


        public string Label
        {
            get { return _label; }
            set
            {
                _label = value;
                OnPropertyChanged("Label");
            }
        }

        public string Value
        {
            get { return _value; }
            set
            {
                _value = value;
                OnPropertyChanged("Value");
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

}
